package com.franklin.validation.core.response;

import com.franklin.validation.core.annotations.Response;
import com.franklin.validation.core.constants.Constants;
import com.franklin.validation.core.utils.SystemClock;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/4 11:14
 */
@Component
@Response(type = Map.class)
public class DefaultMapJsonResponse implements JsonResponse<String,Map<String,String>> {
    @Override
    public Map<String, String> response(String input) {
        String[] split = input.split(Constants.COMMA);
        Map<String,String> result = new HashMap<>(4);
        result.put("timestamp", SystemClock.nowStr());
        result.put("code",split[0]);
        result.put("message",split[1]);
        result.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
        return result;
    }

    @Override
    public Map<String, String> defaultResponse(Class ... type) {
        Map<String,String> result = new HashMap<>(4);
        result.put("timestamp", SystemClock.nowStr());
        result.put("code","500");
        result.put("message","SERVICE ERROR");
        result.put("error", HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
        return result;
    }
}
